<?php

require_once 'db/db.php';

function addUser( $user, $pass, $email ) {
  try {
    $db = openDbConn();

    // validate for spaces and stuff like that
    $user = $db->quote($user);
    $pass = $db->quote($pass);

    $db->exec("INSERT INTO user (name, pass, mail) 
                  VALUES ($user, $pass, $email) ");
    } catch ( PDOException $e ) {
      print "ERROR: " . $e->getMessage() . "<br />";
      die();
    }
}

// string -> bool
function setPerm( $uid, $perm ) {
  try {
    $db = openDbConn();   
 
    $permSearch = $db->quote( $perm . '%' );
    $perm = $db->quote( $perm );
    $db->exec("DELETE FROM perms WHERE perm LIKE $permSearch;
               INSERT INTO perms (uid, perm) VALUES ( $uid, $perm )");
   } catch ( PDOException $e ) {
      print "ERROR: " . $e->getMessage() . "<br />";
      die();
    }
}

?>
